package cn.smile;

import org.checkerframework.checker.nullness.qual.Nullable;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.ExpectedCondition;
import org.openqa.selenium.support.ui.WebDriverWait;

import java.time.Duration;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: 毛苏宇
 * User: me
 * Date: 2021/4/21
 * Time: 0:00
 * Description:
 */
public class ChromeTest {

    public static void main(String[] args) {
        System.setProperty("webdriver.chrome.driver", "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chromedriver.exe");
        WebDriver chrome = new ChromeDriver();
        //设置等待时间
        chrome.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));
        chrome.manage().window().maximize();
        chrome.get("https://gitee.com/");
        //通过超链接文本找到登录按钮并模拟单击打开
        chrome.findElement(By.linkText("登录")).click();
        chrome.findElement(By.id("user_login")).sendKeys("2564800708@qq.com");
        chrome.findElement(By.id("user_password")).sendKeys(PASSWORD);
        chrome.findElement(By.name("commit")).click();
        chrome.findElement(By.id("git-nav-user")).click();
        new WebDriverWait(chrome, Duration.ofSeconds(10)).until(new ExpectedCondition<WebElement>() {
            @Nullable
            @Override
            public WebElement apply(@Nullable WebDriver driver) {
                return driver.findElement(By.id("git-nav-user")).findElements(By.className("item")).get(0);
            }
        }).click();
        ((ChromeDriver) chrome).executeScript("alert('自动化完毕')");
    }


    static final String PASSWORD = "maomao123123";
}
